export default class files {
	static down(url) {
		uni.downloadFile({
			url,
			success: function(res) {
				uni.openDocument({
					filePath: res.tempFilePath,
					showMenu: true,
					success: function(res) {
						console.log('打开文档成功');
					},
					fail: (err) => {
						console.log(err);
					}
				});
			},
			fail: (err) => {
				console.log(err);
			}
		});
	}
	static formatFileStr(list) {
		// const list = str.split(',')
		// const res = []
		// list.forEach(item => {
		// 	const lastIndex = item.lastIndexOf('.');
		// 	const name = item.substring(lastIndex + 1)
		// 	res.push({
		// 		deleteFile: 'deleteFile',
		// 		url: item,
		// 		name
		// 	})
		// })
		
		const res = list.map(({fileName,fileSize,fileUrl})=>({name:fileName,size:fileSize,url:fileUrl}))
		return res
	}
	static getFileNameByUrl(url){
		const lastIndex = url.lastIndexOf('/');
		const result = url.substring(lastIndex + 1);
		return result
	}
	static getFileExtension(filename) {
		const lastIndex = filename.lastIndexOf('.');
		if (lastIndex !== -1) {
			return filename.substring(lastIndex);
		}
		return '';
	}
}